package Message;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-10-18
 * Time: 15:38
 */

class Message {
    public int aa;
    public int bb;
}

@WebServlet("/messageInfo")
public class MessageInfo extends HttpServlet {
//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        resp.setContentType("text/html;charset =utf8");
//        String aa = req.getParameter("aa");
//        String bb = req.getParameter("bb");
//        System.out.println("aa : " + aa + " bb : " + bb);
//        resp.getWriter().write("aa : " + aa + " bb : " + bb);
//    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset =utf8");
        String aa = req.getParameter("aa");
        String bb = req.getParameter("bb");
        System.out.println("aa : " + aa + " bb : " + bb);
        resp.getWriter().write("aa : " + aa + " bb : " + bb);
    }


//    @Override
//    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //使用jackson进行构造post请求进行解析
//        resp.setContentType("text/html;charset =utf8");
//        ObjectMapper objectMapper = new ObjectMapper();
//        Message.Message message = objectMapper.readValue(req.getInputStream(),Message.Message.class);
//        System.out.println("aa : " + message.aa + "bb : " + message.bb);
//        resp.getWriter().write("aa : " + message.aa + " bb : " + message.bb);
//    }
}
